package org.lop.modules.json.jackson.serializer;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 * Double的Json序列化.
 * 
 * @author 潘瑞峥
 * @date 2013-6-3
 */
public class DoubleToStringJsonSerializer extends JsonSerializer<Double> {

	private static final String DOUBLE_FORMAT = "%.2f";

	@Override
	public void serialize( Double value, JsonGenerator jgen, SerializerProvider provider ) throws IOException, JsonProcessingException {
		jgen.writeString( String.format( DOUBLE_FORMAT, value ) );
	}

}